package cn.ittaoli.szdz.controller;

import cn.ittaoli.szdz.model.CxMember;
import cn.ittaoli.szdz.service.CxMemberService;
import com.google.code.kaptcha.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by lub_lenovo on 2017/8/16.
 */
@Controller
@RequestMapping("/login")
public class LoginController {
    @Autowired
    private CxMemberService cxMemberService;

    @RequestMapping("/index")
    public String index(){
        return "/login/index";
    }

    @RequestMapping("/doLogin")
    public String doLogin(CxMember admin,String verify, HttpServletRequest request){
        String codeCorrect=(String)request.getSession().getAttribute(Constants.KAPTCHA_SESSION_KEY);
        if(cxMemberService.doLogin(admin,verify,codeCorrect)){
            return "redirect:/main/index";
        }else{
            return "redirect:/login/index";
        }
    }
}
